package com.example.ibsp_demo.controller.perCenter;

import com.example.ibsp_demo.pojo.dto.perCenter.UserProfileDto;
import com.example.ibsp_demo.pojo.entity.content.Content;
import com.example.ibsp_demo.pojo.entity.content.Favorite;
import com.example.ibsp_demo.pojo.entity.message.FollowNotification;
import com.example.ibsp_demo.pojo.entity.message.UserFeedback;
import com.example.ibsp_demo.pojo.entity.user.User;
import com.example.ibsp_demo.pojo.entity.user.UserProfile;
import com.example.ibsp_demo.pojo.response.ResponseMessage;
import com.example.ibsp_demo.service.PerCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/percenter")
public class PerCenterController {

    @Autowired
    private PerCenterService perCenterService;

    // 1. 查看全部帖子 content 关联 uid
    @GetMapping("/posts")
    public ResponseMessage<List<Content>> getAllPostsByUid(@RequestParam Integer uid) {
        return ResponseMessage.success(perCenterService.getAllPostsByAuid(uid));
    }

    // 2. 编辑个人资料 UserProfile 和 User 里的大部分属性都是可改动的

    @GetMapping("/getProfile")
    public ResponseMessage<UserProfile> getProfile(@RequestParam Integer uid) {
        return ResponseMessage.success(perCenterService.getProfile(uid));
    }

    @PutMapping("/putProfile")
    public ResponseMessage<UserProfile> updateProfile(@RequestBody UserProfileDto dto) {
        perCenterService.updateProfile(dto);
        return ResponseMessage.success(perCenterService.getProfile(dto.getUid()));
    }

    // 3. 粉丝列表：followRelation 关联 uid
    @GetMapping("/followers")
    public ResponseMessage<List<FollowNotification>> getFollowers(@RequestParam Integer uid) {
        return ResponseMessage.success(perCenterService.getFollowers(uid));
    }

//    // 4. 浏览记录（我发现好像还没有这张表），创建一张表专门记录 uid 和 ctid的关系
//    @PostMapping("/view")
//    public void recordView(@RequestParam Integer uid, @RequestParam Integer ctid) {
//        perCenterService.recordView(uid, ctid);
//    }

    // 5.收藏列表 ：Favorite 关联 uid
    @GetMapping("/favorites")
    public ResponseMessage<List<Favorite>> getFavorites(@RequestParam Integer uid) {
        return ResponseMessage.success(perCenterService.getFavorites(uid));
    }

    // 6.注销：反复确认（前端工作），然后执行：user 的 status 变成 3
    @PutMapping("/deactivate")
    public ResponseEntity<String> deactivateUser(@RequestParam Integer uid) {
        perCenterService.deactivateUser(uid);
        return ResponseEntity.ok("注销成功");
    }

    // 7. 反馈与帮助 ，通过user_feed_back 表记录反馈消息，管理员可以看到消息，可能还需要一张表记录是否已读
    @PostMapping("/feedback")
    public ResponseEntity<Object> submitFeedback(@RequestBody UserFeedback userfeedback) {
        perCenterService.submitFeedback(userfeedback);
        return ResponseEntity.ok(userfeedback);
    }

    // 8.隐私设置：设置全部内容不可见，个人信息不可见即可，
    @PutMapping("/privacy")
    public ResponseEntity<Object> updatePrivacySettings(@RequestBody UserProfile profile) {
        perCenterService.updatePrivacySettings(profile);
        return ResponseEntity.ok(profile);

    }

//    // 9.活跃概况 ：记录最近登录情况 ，阅览博客数，互动情况
//    @GetMapping("/activity")
//    public ActivityOverview getActivityOverview(@RequestParam Integer uid) {
//        return perCenterService.getActivityOverview(uid);
//    }
}
